<?php
class Usuario extends AppModel {

	var $name = 'Usuario';
	var $validate = array(
		'grupo_id' => array('notempty'),
		'nombre' => array('notempty'),
		'password_login'=> array('notempty'),
		'password_transaccion'=> array('notempty'),
		'email' => array('email')
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
			'Grupo' => array('className' => 'Grupo',
								'foreignKey' => 'grupo_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			)
	);

	var $hasMany = array(
			'Cuenta' => array('className' => 'Cuenta',
								'foreignKey' => 'usuario_id',
								'dependent' => false,
								'conditions' => '',
								'fields' => '',
								'order' => '',
								'limit' => '',
								'offset' => '',
								'exclusive' => '',
								'finderQuery' => '',
								'counterQuery' => ''
			)
	);

	function validateLogin($data)
    {
        $usuario = $this->find(array('username' => $data['username'], 'passwordlogin' => md5($data['password'])), array('id', 'username'));
        if(empty($usuario) == false)
            return $usuario['Usuario'];
        return false;
    }

}
?>